/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package towerz.component;

import javax.microedition.lcdui.Graphics;

/**
 *
 * @author LegACy
 */
public class TimerLabel {
	protected TimerLabel() {
		//
		m_X			= 0;
		m_Y			= 0;
		m_Limit		= 0;
		m_Timer		= 0;
		m_Factor	= 1;
	}

	public TimerLabel(long initial, int x, int y) {
		this(initial, x, y, false);
	}

	public TimerLabel(long limit, int x, int y, boolean increasing) {
		//Default
		this();

		//Save data
		m_X = x;
		m_Y = y;

		//If increasing
		if (increasing) {
			//Set data
			m_Limit = limit;
		} else {
			//Set data
			m_Timer		= limit;
			m_Factor	= -1;
		}
	}

	public boolean isLimit() {
		return (m_Factor < 0) ? m_Timer <= m_Limit : m_Timer >= m_Limit;
	}

	public void update(long time) {
		//If not on limit yet
		if (!isLimit()) m_Timer += (time * m_Factor);
	}

	public void draw(Graphics g) {
		//Get time
		int Minute			= (int) (m_Timer / 60000);
		int Second			= (int) ((m_Timer % 60000) / 1000);

		//Get text
		String MinuteText	= (Minute < 10 ? "0" : "") + Minute;
		String SecondText	= (Second < 10 ? "0" : "") + Second;

		//Draw
		g.drawString(MinuteText + ":" + SecondText, m_X, m_Y + 2, Graphics.HCENTER | Graphics.TOP);
	}

	//
	protected int m_X;
	protected int m_Y;

	//Timing
	protected int m_Factor;
	protected long m_Limit;
	protected long m_Timer;
}
